package websocket.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import websocket.dto.ResultDTO;
import websocket.entity.vo.DataLogVo;
import websocket.service.DataLogService;
import websocket.util.JwdCalculationUtil;

import java.math.BigDecimal;

/**
 * 计算Controller
 *
 */
@RestController
@RequestMapping("/api/calculation")
@Api(tags = "计算Controller")
public class CalculationController {

    @Autowired
    private  DataLogService dataLogService;

    @GetMapping
    @ApiOperation("根据无人机经纬高、水平仪经纬高计算空间距离（斜距离）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lon1", value = "无人机经度"),
            @ApiImplicitParam(name = "lat1", value = "无人机纬度"),
            @ApiImplicitParam(name = "hgt1", value = "无人机高度"),
            @ApiImplicitParam(name = "lon2", value = "水平仪经度"),
            @ApiImplicitParam(name = "lat2", value = "水平仪纬度"),
            @ApiImplicitParam(name = "hgt2", value = "水平仪高度")
    })
    public ResultDTO openPort(@RequestParam(name = "lon1") Double lon1,
                              @RequestParam(name = "lat1") Double lat1,
                              @RequestParam(name = "hgt1") Double hgt1,
                              @RequestParam(name = "lon2") Double lon2,
                              @RequestParam(name = "lat2") Double lat2,
                              @RequestParam(name = "hgt2") Double hgt2) {
        DataLogVo dataLogVo = new JwdCalculationUtil().jisuan(lon1, lat1, hgt1,
                lon2, lat2, hgt2);
        dataLogService.save(dataLogVo.getDataLog());
        return ResultDTO.success(dataLogVo.getDistanceDecimal());
    }
}
